﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Web;
using Castle.Windsor;
using MvcContrib.Castle;

namespace ThunderJob.Persistence.Dependency
{
    public class ComponentRegistrar
    {
        //public static void AddComponentsTo(IWindsorContainer container)
        //{
        //    container.AddFacility<FactorySupportFacility>();

        //    AddControllersTo(container);
        //    AddGenericRepositoriesTo(container);
        //    AddCustomRepositoriesTo(container);
        //    AddApplicationServicesTo(container);
        //    AddOneOffs(container);
        //    AddSecurityConcernsTo(container);
        //}

        ////add all my controllers
        //private static void AddControllersTo(IWindsorContainer container)
        //{
        //    container.RegisterControllers(typeof(HomeController).Assembly);
        //}

        ////handle registrations for my security classes
        //private static void AddSecurityConcernsTo(IWindsorContainer container)
        //{
        //    container.Register(Component.For<IIdentity>()
        //      .LifeStyle.PerWebRequest
        //      .UsingFactoryMethod(() => HttpContext.Current.User.Identity));

        //    container.Register(Component.For<IPrincipal>()
        //      .LifeStyle.PerWebRequest
        //      .UsingFactoryMethod(() => HttpContext.Current.User));

        //}

        ////register my application services
        //private static void AddApplicationServicesTo(IWindsorContainer container)
        //{
        //    container.Register(
        //        AllTypes.Pick()
        //        .FromAssembly(typeof(ProfileService).Assembly)
        //        .WithService.FirstInterface());
        //}

        ////register all custom repositories (not generic)
        //private static void AddCustomRepositoriesTo(IWindsorContainer container)
        //{
        //    container.Register(
        //        AllTypes.Pick()
        //        .FromAssembly(typeof(UserRepository).Assembly)
        //        .WithService.FirstNonGenericCoreInterface("S2sol.Rpo.Core"));
        //}

        ////register all my SharpArch generic repos
        //private static void AddGenericRepositoriesTo(IWindsorContainer container)
        //{
        //    container.AddComponent("entityDuplicateChecker",
        //        typeof(IEntityDuplicateChecker), typeof(EntityDuplicateChecker));
        //    container.AddComponent("repositoryType",
        //        typeof(IRepository<>), typeof(Repository<>));
        //    container.AddComponent("nhibernateRepositoryType",
        //        typeof(INHibernateRepository<>), typeof(NHibernateRepository<>));
        //    container.AddComponent("repositoryWithTypedId",
        //        typeof(IRepositoryWithTypedId<,>), typeof(RepositoryWithTypedId<,>));
        //    container.AddComponent("nhibernateRepositoryWithTypedId",
        //        typeof(INHibernateRepositoryWithTypedId<,>), typeof(NHibernateRepositoryWithTypedId<,>));

        //}
    }

}
